<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">
		<title>My JSP '008_datagrid.jsp' starting page</title>

		<%@include file="/WEB-INF/jsp/public/commons.jspf"%>
		<link rel="stylesheet"
			href="<%=path%>/js/kindeditor-4.1.7/themes/default/default.css" />
		<link rel="stylesheet"
			href="<%=path%>/js/kindeditor-4.1.7/plugins/code/prettify.css" />
		<link rel="stylesheet"
		href="<%=path%>/css/kpointAdd.css" />
		<script charset="utf-8"
			src="<%=path%>/js/kindeditor-4.1.7/kindeditor.js"></script>
		<script charset="utf-8"
			src="<%=path%>/js/kindeditor-4.1.7/lang/zh_CN.js"></script>
		<script charset="utf-8"
			src="<%=path%>/js/kindeditor-4.1.7/plugins/code/prettify.js"></script>
	<script charset="utf-8"
				src="<%=path%>/js/kpoint/edit.js"></script>
<script type="text/javascript">

		KindEditor.ready(function(K) {
			var editor1 = K.create('#description', {
				cssPath : '<%=path%>/js/kindeditor-4.1.7/plugins/code/prettify.css',
				uploadJson : '<%=path%>/js/kindeditor-4.1.7/jsp/upload_json.jsp',
				fileManagerJson : '<%=path%>/js/kindeditor-4.1.7/jsp/file_manager_json.jsp',
				allowFileManager : true,
			});
			prettyPrint();


			//表单提交
			$("#btn1").click(function(){

				if ($('#myform').form('validate')){
					//同步textarea的数据
					editor1.sync();

					$.ajax({
						type: 'post' ,
						url:'kpoint_edit.action',
						cache:false ,
						data:$('#myform').serialize() ,
						dataType:'json' ,
						success:function(result){
							// 提示信息
							parent.$.messager.show({
								title:result.status , 
								msg:result.message
							});
							parent.closeWin();
							
						} ,
						error:function(result){
							$.messager.show({
								title:result.status , 
								msg:result.message
							});
						}
					});
				}
			});
		});

		$(function(){

			/*初始化导航*/
			$("#nav").combotree( {
				url : 'navigation_listJsonLeft.action',
				valueField : 'name', //数据表格要有主键	
				textField : 'name'
			});

			/**
			 * 	对于form表单的验证 
			 */
			//数值验证组件 
			// 自定义的校验器
			$.extend($.fn.validatebox.defaults.rules,
					{
						midLength : {
							validator : function(value, param) {
								return value.length >= param[0]
										&& value.length <= param[1];
							},
							message : ''
						}
					});

			//数值验证组件 
			$('#period').numberbox( {
				min : 0,
				max : 200,
				required : true,
				missingMessage : '学时必填!',
				precision : 0
			});

			//初始化前导父类知识点
			$("#parentKIds").val('<s:iterator value="model.parentKnowledges" var="pk">${pk.id},</s:iterator>');
			$("#preKIds").val('<s:iterator value="model.preKnowledges" var="pk">${pk.id},</s:iterator>');
			$("#referenceIds").val('<s:iterator value="model.references" var="rs">${rs.id},</s:iterator>');
		});
</script>
<script type="text/javascript">
	
</script>
	</head>

	<body>
			<form id="myform" action="kpoint_edit.action" method="post">
				<s:textfield name="id" type="hidden" value="%{model.id}"/>
				<table>
					<tr>
						<td>
							知识点名:
						</td>
						<td>
							<input type="text" name="name" id="name" class="easyui-validatebox" required=true
								validType="midLength[1,100]" missingMessage="知识点名必填!"
								invalidMessage="必须在100个字符以内!" value="${model.name}"/>
						</td>
					</tr>
  	<tr>
						<td>
							所属分类:
						</td>
						<td>
							<input name="navigation.id"  id="nav" required=true missingMessage="分类必选!" value="${model.navigation.id}"/>
						</td>
					</tr>
					<tr>
				
					<td>
						定义:
					</td>
					<td>
						<textarea type="text" name="definition" id="definition"
							class="easyui-validatebox" required=true
							validType="midLength[1,300]" missingMessage="定义必填!"
							invalidMessage="定义必须在250个字符以内!" >${model.definition}</textarea>
					</td>
					</tr>
					<tr>
						<td>
							难度:
						</td>
						<td>
							<select id="defficulty" name="defficulty" style="width: 200px;"
								name="difficulty" value="${model.defficulty}">
								<option value="1" ${model.defficulty eq 1?'selected': ''}>
									非常简单
								</option>

								<option value="2" ${model.defficulty eq 2?'selected': ''}>
									简单
								</option>

								<option value="3" ${model.defficulty eq 3?'selected': ''}>
									中等
								</option>

								<option value="4" ${model.defficulty eq 4?'selected': ''}>
									困难
								</option>

								<option value="5" ${model.defficulty eq 5?'selected': ''}>
									非常困难
								</option>
							</select>
						</td>
					</tr>

					<tr>
						<td>
							目标:
						</td>
						<td>
							<input type="radio" name="goal" checked="checked" value="${model.goal}" />
							了解
							<input type="radio" name="goal" value="2" />
							掌握
							<input type="radio" name="goal" value="3" />
							应用
						</td>
					</tr>

					<tr>
						<td>
							学时:
						</td>
						<td>
							<input id="period" type="text" name="period"  value="${model.period}"/>
						</td>
					</tr>
					
					<tr>
						<td>
							参考资料：
						</td>
						<td>
							<input id="referenceIds" type="hidden" name="referenceIds" value=""/>
							<div id="referenceTip">
								<s:iterator value="model.references" var="rs">
									<div  class="tipDiv" id="referenceTip${rs.id}">
										<span >${rs.name}</span>
									<a href="javascript:void(0)" title="删除" onclick=delTip("reference","${rs.id}")>×</a>
									</div>
								</s:iterator>
							</div>
							
							<a id="referenceBtn" class="easyui-linkButton" iconCls='icon-add'>添加参考资料</a>
							 <div id="referenceWin" title="请选择参考资料">  
							 	<table id="referenceDataGrid"></table>
							  </div>
						</td>
					</tr>
					

					<tr>
						<td>
							父类知识点:
						</td>
						<td>
							<input id="parentKIds" type="hidden" name="parentKIds" value=""/>
							<div id="parentKTip">
								<s:iterator value="model.parentKnowledges" var="pk">
									<div  class="tipDiv" id="parentKTip${pk.id}">
										<span >${pk.name}</span>
									<a href="javascript:void(0)" title="删除" onclick=delTip("parentK","${pk.id}")>×</a>
									</div>
								</s:iterator>
							</div>
							
							<a id="parentKBtn" class="easyui-linkButton" iconCls='icon-add'>添加父类知识点</a>
							 <div id="parentKWin" title="请选择父类知识点">  
							 	<table id="parentKDataGrid"></table>
							  </div>
						</td>
					</tr>


					<tr>
						<td>
							前导知识点:
						</td>
						<td>
							<input id="preKIds" type="hidden" name="preKIds" value=""/>
							<div id="preKTip">
								<s:iterator value="model.preKnowledges" var="pk">
									<div  class="tipDiv" id="preKTip${pk.id}">
										<span >${pk.name}</span>
									<a href="javascript:void(0)" title="删除" onclick=delTip("preK","${pk.id}")>×</a>
									</div>
								</s:iterator>
							</div>
							<a id="preKBtn" class="easyui-linkButton" iconCls='icon-add'>添加前导知识点</a>
							 <div id="preKWin" title="请选择前导类知识点">
							 	<table id="preKDataGrid"></table>
							 </div>
						</td>
					</tr>

					<tr>
						<td>
							描述:
						</td>
						<td>
							<textarea name="description" id="description" cols="50" rows="8" style="width:700px;height:200px;visibility:hidden;" class="easyui-validatebox" 
								missingMessage="描述必填!">
							${model.description}
							</textarea>
						</td>
					</tr>
					<tr align="center">
						<td colspan="2">
							<a id="btn1"class="easyui-linkbutton">确定</a>
							<a id="btn2" class="easyui-linkbutton">关闭</a>
						</td>
					</tr>
				</table>
			</form>
	</body>
</html>
